struct ListNode* deleteDuplicates(struct ListNode* head) {
    struct ListNode *p=head,*q,*t=head,*m,*k;
    if(p==NULL)
    return NULL;
    q=p->next;
    if(q==NULL)
    return head;
    while(p->val==q->val)
    {
        while(p->val==q->val)
        {
            p=p->next;
            q=q->next;
            if(q==NULL)
            return NULL;
            
        }
        p=p->next;
        q=q->next;
        if(q==NULL)
        {
            head=p;
            return head;
        }
        
    }
    head=p;
    while(t!=head)
    {
        m=t->next;
        free(t);
        t=m;
    }
    p=head->next;
    if(p==NULL)
        return head;
    q=p->next;
    
        k=head;





    while(q!=NULL)
    {
    if(p->val==q->val)
        {
        while(p->val==q->val)
            {t=q;
            q=q->next;
            if(q==NULL)
                {
                    while(p->next!=NULL)
                    {
                        m=p->next;
                    free(p);
                    p=m;
                    }
                    free(p);
                    k->next=NULL;
                    return head;
                
                }
            }
            /**/while(p!=t)
            {m=p->next;
            free(p);
            p=m;
            } 
            free(t);
            
        p=q;
            q=p->next;
           
            k->next=p;  
        
        }
    else
    {
        k=k->next;
        p=p->next;
        q=q->next;
    }
  }
   
    return head;

}